<?php
class Seminar_catalogue extends CI_Controller{
	public function __construct(){
		parent::__construct();
		if(!isset($_SESSION)){
			session_start();
		}
		$this->load->helper(array('form', 'url'));
		$this->load->model('seminar_model');
	}
	
	public function index(){
		$data['title'] = 'Seminar Catalogue';
		$this->load->view('templates/header',$data);
		$this->load->view('templates/footer');
	}
	
	public function upload(){
		$this->load->helper('form');
		$this->load->library('form_validation');
	
		$data['title'] = 'New Seminar Form';
	
		$this->form_validation->set_rules('topic', 'Topic', 'required');
		$this->form_validation->set_rules('desc', 'Description', 'required');
		$this->form_validation->set_rules('sDate', 'Date', 'required');
	
		if ($this->form_validation->run() === FALSE)
		{
			$this->load->view('templates/header', $data);
			$this->load->view('seminar/create_seminar');
			$this->load->view('templates/footer');
	
		}
		else
		{
			$config['upload_path'] = realpath(APPPATH . '/uploads');
			$config['allowed_types'] = 'ppt|pptx';
			$config['max_size']	= '4096';
			$this->load->library('upload');
			$this->upload->initialize($config);

			if ( ! $this->upload->do_upload())
			{
				$error = array('error' => $this->upload->display_errors());
	
				$this->load->view('seminar/create_seminar', $error);
			}
			else
			{
				$data = $this->upload->data();
				$this->seminar_model->create_seminar($data['full_path']);
				$this->load->view('templates/header', $data);
				$this->load->view('templates/footer');
			}
		}
	}

	public function get_seminars(){
		$data['title'] = 'Seminar List';
		$data['result'] = $this->seminar_model->get_seminars();
		$this->load->view('templates/header', $data);
		$this->load->view('seminar/seminar_list', $data);
		$this->load->view('templates/footer');			
	}
	
	public function view_seminar($id=0){
		if(!$id==0) {
			$data['result'] = $this->seminar_model->get_seminar($id);
//			$data['title'] = $data['result']['topic'];
			$data['title'] = 'Seminar Info';
			$this->load->view('templates/header', $data);
			$this->load->view('seminar/seminar_info', $data);
			$this->load->view('templates/footer');
		} else{ show_404();}
	}
	
	public function get_registered_seminars(){
		if(isset($_SESSION['user_id'])){
			$data['title'] = 'My upcoming seminars';
			$data['result'] = $this->seminar_model->get_registered_seminars($_SESSION['user_id']);
			$this->load->view('templates/header', $data);
			$this->load->view('seminar/seminar_list', $data);
			$this->load->view('templates/footer');			
		}
		else if(!isset($_SESSION['username'])){
			$data['title'] = 'Please login to continue';
			$this->load->view('templates/header', $data);
			$this->load->view('pages/home', $data);
			$this->load->view('templates/footer');
		}
		else{
			$data['title'] = 'Unauthorized Access';
			$this->load->view('templates/header', $data);
			$this->load->view('pages/no_access');
			$this->load->view('templates/footer');
		}

	}
	
	public function get_attended_seminars(){
		if(isset($_SESSION['user_id'])){
			$data['title'] = 'My attended seminars';
			$data['result'] = $this->seminar_model->get_attended_seminars($_SESSION['user_id']);
			$this->load->view('templates/header', $data);
			$this->load->view('seminar/seminar_list', $data);
			$this->load->view('templates/footer');			
		}
		else if(!isset($_SESSION['username'])){
			$data['title'] = 'Please login to continue';
			$this->load->view('templates/header', $data);
			$this->load->view('pages/home', $data);
			$this->load->view('templates/footer');
		}
		else{
			$data['title'] = 'Unauthorized Access';
			$this->load->view('templates/header', $data);
			$this->load->view('pages/no_access');
			$this->load->view('templates/footer');
		}

	}
	
	public function register($id=0){
		if(!$id==0) {
			$data['title'] = 'Registered for seminar# '. $id;
			$this->seminar_model->register($id);			
			$this->load->view('templates/header', $data);
			$this->load->view('attendee/attendee_dashboard', $data);
			$this->load->view('templates/footer');
		} else{ show_404();}
	}
}
?>